﻿using Microsoft.AspNetCore.Mvc;
using Mysoft.Common.Exceptions;
using Mysoft.Common.Extensions;
using Mysoft.Data.CacheManager.IService;
using Mysoft.Data.UserManager;

namespace Mysoft.Domain.Basic
{
    /// <summary>
    ///  DomainBase
    /// </summary>
    public abstract class DomainBase
    {
        /// <summary>
        /// 无参构造
        /// </summary>
        public DomainBase() { 
        
        }
        /// <summary>
        /// 缓存服务
        /// </summary>
        protected internal ICacheService _CacheContext
        {
            get
            {
                return HttpContext.Current.RequestServices.GetService(typeof(ICacheService)) as ICacheService;
            }
        }
        /// <summary>
        /// 当前用户
        /// </summary>
        protected internal UserContext _UserContext
        {
            get
            {
                return HttpContext.Current.RequestServices.GetService(typeof(UserContext)) as UserContext;
            }
        }

        /// <summary>
        /// 抛出异常
        /// </summary>
        /// <param name="message"></param>
        /// <param name="statusCode"></param>
        /// <returns></returns>
        protected internal JsonResult BusinessException(string message)
        {
            throw new BusinessException(message);
        }

    }
}
